/**
 * 自定义的枚举类默认继承 Enum抽象类
 * 其构造方法默认是私有的
 * 枚举类不能被继承 --- 构造方法是私有的
 */
public enum TestEnum {
    // 枚举对象 属于 对象，无参构造的()可以省略
    RED("red",0),GREEN("green",1),BLACK("black",2),WHITE("white",3);

    public String color;
    public int ordinal;

    // 构造方法默认是私有的
    private TestEnum(String color, int ordinal) {
        this.color = color;
        this.ordinal = ordinal;
    }
//    TestEnum(){
//
//    }

    public static void main(String[] args) {

    }

    public static void main3(String[] args) {
        TestEnum red = TestEnum.valueOf("RED");
        System.out.println(red);

        System.out.println(red.compareTo(GREEN));// 通过索引比较的
        //            return self.ordinal - other.ordinal;
    }

    public static void main2(String[] args) {
        TestEnum[] values = TestEnum.values();
        for (TestEnum t:values) {
            System.out.println(t + " -> " + t.ordinal());// 获得枚举和索引
        }
    }

    public static void main1(String[] args) {
        TestEnum testEnum2 = TestEnum.BLACK;
        switch (testEnum2) {
            case RED:
                System.out.println("red!");
                break;
            case BLACK:
                System.out.println("black!");
                break;
            case WHITE:
                System.out.println("white!");
                break;
            case GREEN:
                System.out.println("green!");
                break;
            default:
                break;
        }
    }
}
